package com.ccys.common.enums;

import com.ccys.common.constants.ContextConstants;

/**
 * CodeEnum
 * <p>
 **/
public enum CodeEnum {

    //HTTP
    NO_HANDLER(404, "请求不存在"),
    SUCCESSFUL(200, "请求成功"),
    FAIL(888, "请求失败"),
    ERROR(403, "请求失败"),
    OPT_NO_SUPPORT(400, "当前状态不允许操作"),
    NO_AUTH(401, "登陆未授权"),
    ILLEGAL(411, ContextConstants.DESC_411),
    UNDEFINED(0xFFFF, "未知异常"),

    //order 排序 + "空格" 可附带参数
    ASC(0xEE, "create_time ASC "),
    DESC(0xFF, "create_time DESC "),

    // 文件上传
    UPLOAD_IMG_ERROR(0xB001, "图片上传失败"),
    UPLOAD_FILE_ERROR(0xB002, "文件上传失败"),

    // page
    PAGE_OFFSET(0, "偏移量"),
    PAGE_LIMIT(10, "页大小"),
    PAGE_NUM(1, "开始页"),
    PAGE_SIZE(10, "页大小"),

    //缓存库
    REDIS_USER(0, "user"),
    REDIS_SYS_CODE(1, "code:"),
    REDIS_SYS_MODULE(2, "sys_module"),
    REDIS_MSG_CODE(3, "msgCode"),
    REDIS_SECURE(4, "secure"),

    //缓存刷新回调
    REFRESH_MODULE(5, "refresh_module"),

    //接口请求路径
    REDIS_API_PATH(6, "api_path"),
    REDIS_TRANSLATION(7, "translation"),

    REDIS_UPDATE_PROFILE(8,"updateProfile"),

    REDIS_BOOKING(9,"booking"),
    //心跳资源库
    REDIS_HEARTBEAT(10,"heartbeat"),

    // 第三方
    REDIS_THIRD(13, "第三方"),

    REDIS_LOCK(14,"lock");

    private Integer code;
    private String msg;

    CodeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer codeOf() {
        return this.code;
    }

    public String msgOf() {
        return this.msg;
    }

    public static CodeEnum get(int value) {
        for (CodeEnum code : values()) {
            if (code.codeOf() == value) {
                return code;
            }
        }
        return null;
    }
}
